﻿namespace Serializator.Composits
{
    using System;
    using Serializator.JSONObjects;

    public class Adress : IAssignable
    {
        #region Constructors

        public Adress()
            : this(0, string.Empty, string.Empty, string.Empty, 0)
        {
        }

        public Adress(Adress a)
            : this(a.Index, a.Country, a.City, a.Street, a.HouseNumber)
        {
        }

        public Adress(int index, string country, string city, string street, int houseNumber)
        {
            Index = index;
            Country = country;
            City = city;
            Street = street;
            HouseNumber = houseNumber;
        }
        #endregion Constructors

        #region IAssignable implementation

        public void AssignTo(object obj)
        {
            if (obj == null)
                throw new ArgumentNullException();

            if (obj is Adress)
            {
                Adress a = obj as Adress;
                a.City = City;
                a.Country = Country;
                a.HouseNumber = HouseNumber;
                a.Index = Index;
                a.Street = Street;

                return;
            }

            if (obj is JSONObject)
            {
                JSONObject result = obj as JSONObject;
                JSONSerializer ser = new JSONSerializer();
                result.EncodedStreamList = ser.Serialize(this).EncodedStreamList;

                return;
            }

            throw new NotSupportedException();
        }

        #endregion

        #region Properties

        public int Index { get; set; }
        public string Country { get; set; }
        public string City { get; set; }
        public string Street { get; set; }
        public int HouseNumber { get; set; }

        #endregion Properties

    }
}
